<template>
  <PageContainer>
    <Header title="数据统计" />
    <view>
      <view class="hb-px-4 hb-py-3 hb-flex hb-items-center">
        <TmImage
          class="hb-mr-2"
          :src="userInfo?.aiUserAccountBotVo.iconFileUrl"
          :width="56"
          :height="56"
          :round="4"
          error-img-type="person"
        />
        <TmText _class="hb-font-bold" :label="userInfo?.aiUserAccountBotVo.name" :font-size="32" />
      </view>
      <template v-for="item in statistics" :key="item.id">
        <view class=" hb-bg-white hb-rounded-xl hb-box-shadow-base hb-mx-4 hb-mt-4">
          <TmText _class="hb-font-bold hb-py-3 hb-px-4" :label="item.title" :font-size="32" />
          <view class="hb-px-3 hb-flex hb-items-center">
            <template v-for="(v, index) in item.list" :key="index">
              <view class="hb-h-20 hb-flex hb-flex-col hb-items-center hb-justify-center hb-flex-1">
                <TmText _class="hb-mb-1 hb-font-bold" :label="(v.value || 0).toString()" :font-size="36" />
                <TmText :label="v.subTitle" color="#969799" :font-size="24" />
              </view>
            </template>
          </view>
        </view>
      </template>
    </view>
  </PageContainer>
</template>

<script lang="ts" setup>
  /* dataStatistics 数据统计 */
  import { useUserStore } from '@/store/modules/user';
  import { getBotStatistics } from '@/api/aiSettings';
  import { BotStatisticsResult } from '@/api/aiSettings/types';

  const useUser = useUserStore();
  const { userInfo } = storeToRefs(useUser);

  const statistics = ref([
    {
      id: 1,
      title: '今日数据',
      list: [
        {
          value: 0,
          subTitle: '查看名片人数',
        },
        {
          value: 0,
          subTitle: '对话人数',
        },
        {
          value: 0,
          subTitle: '对话条数',
        },
      ],
    },
    {
      id: 2,
      title: '汇总数据',
      list: [
        {
          value: 0,
          subTitle: '查看名片人数',
        },
        {
          value: 0,
          subTitle: '对话人数',
        },
        {
          value: 0,
          subTitle: '对话条数',
        },
      ],
    },
  ]);

  // 获取智能体统计数据
  const getStatisticsData = async () => {
    try {
      const res = await getBotStatistics();
      // 更新今日数据
      statistics.value[0].list[0].value = res.browseDayCount;
      statistics.value[0].list[1].value = res.dayChatPeopleNum;
      statistics.value[0].list[2].value = res.dayChatNum;
      
      // 更新汇总数据
      statistics.value[1].list[0].value = res.browseTotalNum;
      statistics.value[1].list[1].value = res.chatPeopleTotalNum;
      statistics.value[1].list[2].value = res.chatTotalNum;
    } catch (error) {
      console.error('获取统计数据失败', error);
    }
  };

  getStatisticsData();

</script>

<style lang="scss" scoped></style>
